package push;

import helper.ImageData;

import javax.media.jai.JAI;

import framework.filters.AbstractActiveFilter;
import framework.pipes.PullPipe;
import framework.pipes.PushPipe;

/**
 * Reads the image from a given source (string is the path) This class extends
 * the abstractActivFilter because we want to use push pipe
 * 
 * @author Wetzel & Rusch
 * 
 */
public class ImageReader extends AbstractActiveFilter<ImageData, ImageData> {

	private String m_image = null;
	private final ImageData m_plImage = new ImageData();

	public ImageReader(PullPipe<ImageData> pullPipe,
			PushPipe<ImageData> pushPipe) {
		super(pullPipe, pushPipe);
	}

	public void setImage(String file) {
		m_image = file;
	}

	public void ReadImager() {
		m_plImage.setOriginalImage(JAI.create("fileload", m_image));

	}

	@Override
	public void doIt() {
		ReadImager();
	}

	@Override
	/**
	 * Start a thread with his own instance 
	 * Afterwards the processing starts
	 */
	public void startThread() {
		Runnable activeFilter = this;
		new Thread(activeFilter).start();
	}

	@Override
	public void run() {
		doIt();
		// Check if an image exists
		if (m_plImage != null) {
			push(m_plImage);
		}

	}
}
